<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail" >
        <a-row>
          <a-col :span="6">
            <a-form-model-item label="审批表名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tableName">
              <a-input v-model="model.tableName" placeholder="请输入审批表名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="审批记录主键" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tableRecordId">
              <a-input v-model="model.tableRecordId" placeholder="请输入审批记录主键"  ></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="6">
            <a-form-model-item label="主表主键列名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainIdColName">
              <a-input v-model="model.mainIdColName" placeholder="请输入主表主键列名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="结果列名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="resultColName">
              <a-input v-model="model.resultColName" placeholder="请输入结果列名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="意见列名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yijianColName">
              <a-input v-model="model.yijianColName" placeholder="请输入意见列名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="时间列名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="timeColName">
              <a-input v-model="model.timeColName" placeholder="请输入时间列名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="日志列名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logColName">
              <a-input v-model="model.logColName" placeholder="请输入日志列名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="审批人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shenpiBy">
              <a-input v-model="model.shenpiBy" placeholder="请输入审批人"  ></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="6">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shenqinBy">
              <a-input v-model="model.shenqinBy" placeholder="请输入申请人"  ></a-input>
            </a-form-model-item>
          </a-col>
          
          <a-col :span="6">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shenqinTime">
              <a-input v-model="model.shenqinTime" placeholder="请输入申请时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          
          <a-col :span="6">
            <a-form-model-item label="备注说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          
          <a-col :span="6">
            <a-form-model-item label="单据类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billType">
              <a-input v-model="model.billType" placeholder="请输入单据类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billNo">
              <a-input v-model="model.billNo" placeholder="请输入单据编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="单据名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billName">
              <a-input v-model="model.billName" placeholder="请输入单据名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="审批节点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jiedianOrdinal">
              <a-input-number v-model="model.jiedianOrdinal" placeholder="请输入审批节点" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="审批节点名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jiedianName">
              <a-input v-model="model.jiedianName" placeholder="请输入审批节点名"  ></a-input>
            </a-form-model-item>
          </a-col>

          
          <a-col :span="6">
            <a-form-model-item label="详情链接" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detailUrl">
              <a-input v-model="model.detailUrl" placeholder="请输入详情链接"  ></a-input>
            </a-form-model-item>
          </a-col>
    
          <a-col :span="6">
            <a-form-model-item label="审批结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signResult">
              <a-input v-model="model.signResult" placeholder="请输入审批结果"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="审批意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signYijian">
              <a-input v-model="model.signYijian" placeholder="请输入审批意见"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ComApprovalListForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/oa/comApprovalList/add",
          edit: "/oa/comApprovalList/edit",
          queryById: "/oa/comApprovalList/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>